/*   1:    */ package org.intellij.plugins.relaxNG.compact.psi.impl;
/*   2:    */ 
/*   3:    */

import com.intellij.icons.AllIcons.Nodes;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.PsiReferenceBase;
import com.intellij.psi.meta.PsiMetaData;
import com.intellij.psi.meta.PsiMetaOwner;
import com.intellij.psi.meta.PsiPresentableMetaData;
import com.intellij.util.ArrayUtil;
import com.intellij.util.IncorrectOperationException;
import org.intellij.plugins.relaxNG.compact.RncTokenTypes;
import org.intellij.plugins.relaxNG.compact.psi.*;
import org.intellij.plugins.relaxNG.compact.psi.util.EscapeUtil;
import org.intellij.plugins.relaxNG.compact.psi.util.RenameUtil;
import org.intellij.plugins.relaxNG.model.resolve.DefinitionResolver;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.Map;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */
/*  24:    */
/*  25:    */
/*  26:    */
/*  27:    */
/*  28:    */
/*  29:    */
/*  30:    */
/*  31:    */ 
/*  32:    */ public class RncDefineImpl
/*  33:    */   extends RncElementImpl
/*  34:    */   implements RncDefine, PsiMetaOwner
/*  35:    */ {
/*  36:    */   public RncDefineImpl(ASTNode paramASTNode)
/*  37:    */   {
/*  38: 51 */     super(paramASTNode);
/*  39:    */   }
/*  40:    */   
/*  41:    */   public void accept(@NotNull RncElementVisitor paramRncElementVisitor)
/*  42:    */   {
/*  43: 55 */     if (paramRncElementVisitor == null) {
/*  44: 55 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/plugins/relaxNG/compact/psi/impl/RncDefineImpl", "accept" }));
/*  45:    */     }
/*  46: 55 */     paramRncElementVisitor.visitDefine(this);
/*  47:    */   }
/*  48:    */   
/*  49:    */   public void accept(CommonElement.Visitor paramVisitor)
/*  50:    */   {
/*  51: 59 */     paramVisitor.visitDefine(this);
/*  52:    */   }
/*  53:    */   
/*  54:    */   public String getName()
/*  55:    */   {
/*  56: 64 */     ASTNode localASTNode = getNameNode();
/*  57: 65 */     return EscapeUtil.unescapeText(localASTNode);
/*  58:    */   }
/*  59:    */   
/*  60:    */   public PsiElement getNameElement()
/*  61:    */   {
/*  62: 69 */     return getNameNode().getPsi();
/*  63:    */   }
/*  64:    */   
/*  65:    */   @NotNull
/*  66:    */   public ASTNode getNameNode()
/*  67:    */   {
/*  68: 74 */     ASTNode localASTNode = getNode().findChildByType(RncTokenTypes.IDENTIFIERS);
/*  69: 75 */     assert (localASTNode != null); ASTNode 
/*  70: 76 */       tmp32_31 = localASTNode;
/*  71: 76 */     if (tmp32_31 == null) {
/*  72: 76 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/compact/psi/impl/RncDefineImpl", "getNameNode" }));
/*  73:    */     }
/*  74: 76 */     return tmp32_31;
/*  75:    */   }
/*  76:    */   
/*  77:    */   public PsiElement setName(@NonNls @NotNull String paramString)
/*  78:    */     throws IncorrectOperationException
/*  79:    */   {
/*  80: 80 */     if (paramString == null) {
/*  81: 80 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/plugins/relaxNG/compact/psi/impl/RncDefineImpl", "setName" }));
/*  82:    */     }
/*  83: 80 */     ASTNode localASTNode = getNameNode();
/*  84: 81 */     localASTNode.getTreeParent().replaceChild(localASTNode, RenameUtil.createIdentifierNode(getManager(), paramString));
/*  85: 82 */     return this;
/*  86:    */   }
/*  87:    */   
/*  88:    */   @Nullable
/*  89:    */   public RncPattern getPattern()
/*  90:    */   {
/*  91: 87 */     return (RncPattern)findChildByClass(RncPattern.class);
/*  92:    */   }
/*  93:    */   
/*  94:    */   public PsiReference getReference()
/*  95:    */   {
/*  96: 91 */     if ((getParent() instanceof RncInclude))
/*  97:    */     {
/*  98: 92 */       TextRange localTextRange = TextRange.from(0, getNameNode().getTextLength());
/*  99: 93 */       new PsiReferenceBase(this, localTextRange, true)
/* 100:    */       {
/* 101:    */         public PsiElement resolve()
/* 102:    */         {
/* 103: 95 */           return RncDefineImpl.this;
/* 104:    */         }
/* 105:    */         
/* 106:    */         @NotNull
/* 107:    */         public Object[] getVariants()
/* 108:    */         {
/* 109:100 */           RncInclude localRncInclude = (RncInclude)RncDefineImpl.this.getParent();
/* 110:101 */           RncFile localRncFile = localRncInclude.getReferencedFile();
/* 111:102 */           if (localRncFile == null)
/* 112:    */           {
/* 113:103 */             PsiReference[] tmp25_22 = EMPTY_ARRAY;
/* 114:103 */             if (tmp25_22 == null) {
/* 115:103 */               throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/compact/psi/impl/RncDefineImpl$1", "getVariants" }));
/* 116:    */             }
/* 117:103 */             return tmp25_22;
/* 118:    */           }
/* 119:105 */           RncGrammar localRncGrammar = localRncFile.getGrammar();
/* 120:106 */           if (localRncGrammar == null)
/* 121:    */           {
/* 122:107 */             PsiReference[] tmp74_71 = EMPTY_ARRAY;
/* 123:107 */             if (tmp74_71 == null) {
/* 124:107 */               throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/compact/psi/impl/RncDefineImpl$1", "getVariants" }));
/* 125:    */             }
/* 126:107 */             return tmp74_71;
/* 127:    */           }
/* 128:110 */           Map localMap = DefinitionResolver.getAllVariants(localRncGrammar);
/* 129:111 */           if (localMap != null)
/* 130:    */           {
/* 131:112 */             Object[] tmp132_127 = localMap.keySet().toArray();
/* 132:112 */             if (tmp132_127 == null) {
/* 133:112 */               throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/compact/psi/impl/RncDefineImpl$1", "getVariants" }));
/* 134:    */             }
/* 135:112 */             return tmp132_127;
/* 136:    */           }
/* 137:114 */           PsiReference[] tmp170_167 = EMPTY_ARRAY;
/* 138:114 */           if (tmp170_167 == null) {
/* 139:114 */             throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/compact/psi/impl/RncDefineImpl$1", "getVariants" }));
/* 140:    */           }
/* 141:114 */           return tmp170_167;
/* 142:    */         }
/* 143:    */       };
/* 144:    */     }
/* 145:118 */     return super.getReference();
/* 146:    */   }
/* 147:    */   
/* 148:    */   @Nullable
/* 149:    */   public Icon getIcon(int paramInt)
/* 150:    */   {
/* 151:123 */     return AllIcons.Nodes.Property;
/* 152:    */   }
/* 153:    */   
/* 154:    */   public boolean isMetaEnough()
/* 155:    */   {
/* 156:127 */     return true;
/* 157:    */   }
/* 158:    */   
/* 159:    */   @Nullable
/* 160:    */   public PsiMetaData getMetaData()
/* 161:    */   {
/* 162:132 */     return new MyMetaData(null);
/* 163:    */   }
/* 164:    */   
/* 165:    */   private class MyMetaData
/* 166:    */     implements PsiMetaData, PsiPresentableMetaData
/* 167:    */   {
/* 168:    */     private MyMetaData() {}
/* 169:    */     
/* 170:    */     @Nullable
/* 171:    */     public Icon getIcon()
/* 172:    */     {
/* 173:142 */       return RncDefineImpl.this.getIcon(0);
/* 174:    */     }
/* 175:    */     
/* 176:    */     public String getTypeName()
/* 177:    */     {
/* 178:146 */       return "Pattern Definition";
/* 179:    */     }
/* 180:    */     
/* 181:    */     public PsiElement getDeclaration()
/* 182:    */     {
/* 183:150 */       return RncDefineImpl.this;
/* 184:    */     }
/* 185:    */     
/* 186:    */     @NonNls
/* 187:    */     public String getName(PsiElement paramPsiElement)
/* 188:    */     {
/* 189:155 */       return RncDefineImpl.this.getName();
/* 190:    */     }
/* 191:    */     
/* 192:    */     @NonNls
/* 193:    */     public String getName()
/* 194:    */     {
/* 195:160 */       return RncDefineImpl.this.getName();
/* 196:    */     }
/* 197:    */     
/* 198:    */     public void init(PsiElement paramPsiElement) {}
/* 199:    */     
/* 200:    */     public Object[] getDependences()
/* 201:    */     {
/* 202:167 */       return ArrayUtil.EMPTY_OBJECT_ARRAY;
/* 203:    */     }
/* 204:    */   }
/* 205:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.compact.psi.impl.RncDefineImpl

 * JD-Core Version:    0.7.0.1

 */